package com.elbis.access.wg.api.response.account;

import java.util.Date;

import com.elbis.access.util.DateUtil;
import com.elbis.access.wg.api.response.WOTResponseEntity;
import com.google.gson.annotations.SerializedName;

public class PersonalData extends WOTResponseEntity {

	private static final long serialVersionUID = 7643978237219810436L;

	private Long account_id = null;

	private Long clan_id = null;

	private String client_language = null;

	private Date created_at = null;

	private Long global_rating = null;

	private Date last_battle_time = null;

	private Date logout_at = null;

	private String nickname = null;

	private Date updated_at = null;

	@SerializedName("private")
	private PrivateData privateData = null;

	private Statistics statistics = null;

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("[");
		builder.append("accountId=");
		builder.append(account_id);
		builder.append("|");
		builder.append("nickname=");
		builder.append(nickname);
		builder.append("|");
		builder.append("clanId=");
		builder.append(clan_id);
		builder.append("|");
		builder.append("clientLanguage=");
		builder.append(client_language);
		builder.append("|");
		builder.append("createdAt=");
		builder.append(DateUtil.formatDate(created_at));
		builder.append("|");
		builder.append("globalRating=");
		builder.append(global_rating);
		builder.append("|");
		builder.append("lastBattleAt=");
		builder.append(DateUtil.formatDateTime(last_battle_time));
		builder.append("|");
		builder.append("logoutAt=");
		builder.append(DateUtil.formatDateTime(logout_at));
		builder.append("|");
		builder.append("updatedAt=");
		builder.append(DateUtil.formatDateTime(updated_at));
		builder.append("]");
		return builder.toString();
	}

	/**
	 * @return the account_id
	 */
	public Long getAccount_id() {
		return account_id;
	}

	/**
	 * @param account_id
	 *            the account_id to set
	 */
	public void setAccount_id(Long account_id) {
		this.account_id = account_id;
	}

	/**
	 * @return the clan_id
	 */
	public Long getClan_id() {
		return clan_id;
	}

	/**
	 * @param clan_id
	 *            the clan_id to set
	 */
	public void setClan_id(Long clan_id) {
		this.clan_id = clan_id;
	}

	/**
	 * @return the client_language
	 */
	public String getClient_language() {
		return client_language;
	}

	/**
	 * @param client_language
	 *            the client_language to set
	 */
	public void setClient_language(String client_language) {
		this.client_language = client_language;
	}

	/**
	 * @return the created_at
	 */
	public Date getCreated_at() {
		return created_at;
	}

	/**
	 * @param created_at
	 *            the created_at to set
	 */
	public void setCreated_at(Date created_at) {
		this.created_at = created_at;
	}

	/**
	 * @return the global_rating
	 */
	public Long getGlobal_rating() {
		return global_rating;
	}

	/**
	 * @param global_rating
	 *            the global_rating to set
	 */
	public void setGlobal_rating(Long global_rating) {
		this.global_rating = global_rating;
	}

	/**
	 * @return the last_battle_time
	 */
	public Date getLast_battle_time() {
		return last_battle_time;
	}

	/**
	 * @param last_battle_time
	 *            the last_battle_time to set
	 */
	public void setLast_battle_time(Date last_battle_time) {
		this.last_battle_time = last_battle_time;
	}

	/**
	 * @return the logout_at
	 */
	public Date getLogout_at() {
		return logout_at;
	}

	/**
	 * @param logout_at
	 *            the logout_at to set
	 */
	public void setLogout_at(Date logout_at) {
		this.logout_at = logout_at;
	}

	/**
	 * @return the nickname
	 */
	public String getNickname() {
		return nickname;
	}

	/**
	 * @param nickname
	 *            the nickname to set
	 */
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	/**
	 * @return the updated_at
	 */
	public Date getUpdated_at() {
		return updated_at;
	}

	/**
	 * @param updated_at
	 *            the updated_at to set
	 */
	public void setUpdated_at(Date updated_at) {
		this.updated_at = updated_at;
	}

	/**
	 * @return the privateDate
	 */
	public PrivateData getPrivateData() {
		return privateData;
	}

	/**
	 * @param privateData
	 *            the privateDate to set
	 */
	public void setPrivateData(PrivateData privateData) {
		this.privateData = privateData;
	}

	/**
	 * @return the statistics
	 */
	public Statistics getStatistics() {
		return statistics;
	}

	/**
	 * @param statistics
	 *            the statistics to set
	 */
	public void setStatistics(Statistics statistics) {
		this.statistics = statistics;
	}

	public Long getBattles() {
		if (statistics != null) {
			if (statistics.getAll() != null) {
				Long battles = statistics.getAll().getBattles();
				if (battles == null) {
					battles = 0L;
				}
				return battles;
			}
		}
		return 0l;
	}

	public Float getKillPerBattle() {
		if (statistics != null) {
			if (statistics.getAll() != null) {
				Long battles = getBattles();
				if (battles == 0) {
					return 0f;
				}
				Long kills = statistics.getAll().getFrags();
				Float ratio = (float) kills / battles;
				return ratio;
			}
		}
		return 0f;
	}

	public Float getDamagePerBattle() {
		if (statistics != null) {
			if (statistics.getAll() != null) {
				Long battles = getBattles();
				if (battles == 0) {
					return 0f;
				}
				Long damage = statistics.getAll().getDamage_dealt();
				Float ratio = (float) damage / battles;
				return ratio;
			}
		}
		return 0f;
	}

	public Float getSpotPerBattle() {
		if (statistics != null) {
			if (statistics.getAll() != null) {
				Long battles = getBattles();
				if (battles == 0) {
					return 0f;
				}
				Long spots = statistics.getAll().getSpotted();
				Float ratio = (float) spots / battles;
				return ratio;
			}
		}
		return 0f;
	}

	public Float getWinRate() {
		if (statistics != null) {
			if (statistics.getAll() != null) {
				Long battles = getBattles();
				if (battles == 0) {
					return 0f;
				}
				Long wins = statistics.getAll().getWins();
				Float ratio = (float) wins / battles;
				return ratio;
			}
		}
		return 0f;
	}

	public Float getDamageRatio() {
		if (statistics != null) {
			if (statistics.getAll() != null) {
				Long damageDealt = statistics.getAll().getDamage_dealt();
				Long damageReceived = statistics.getAll().getDamage_received();
				if (damageReceived == 0) {
					return 0f;
				}
				Float ratio = (float) damageDealt / damageReceived;
				return ratio;
			}
		}
		return 0f;
	}

	public Float getKillRatio() {
		if (statistics != null) {
			if (statistics.getAll() != null) {
				Long kills = statistics.getAll().getFrags();
				Long battles = getBattles();
				if (battles == 0) {
					return 0f;
				}
				Long deaths = battles
						- statistics.getAll().getSurvived_battles();
				if(deaths == 0){
					return Float.POSITIVE_INFINITY;
				}
				Float ratio = (float) kills / deaths;
				return ratio;
			}
		}
		return 0f;
	}

	public Float getAverageXP() {
		if (statistics != null) {
			if (statistics.getAll() != null) {
				return (float) statistics.getAll().getBattle_avg_xp();
			}
		}
		return 0f;
	}

}
